package com.clothe.service;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import com.clothe.dao.IOrderDetialDAO;
import com.clothe.dao.impl.OrderDetialDAOImpl;
import com.clothe.database.DataBase;
import com.clothe.dto.OrderDetial;

public class OrderDetialService {
	Connection connection = null;
	IOrderDetialDAO orderDetialImpl = new OrderDetialDAOImpl();

	public boolean save(OrderDetial orderDetial) throws Exception {
		Connection connection = null;
		boolean flag = false;
		try {
			connection = DataBase.getConn();
			orderDetialImpl.setConn(connection);
			flag = orderDetialImpl.save(orderDetial);
			DataBase.commit();
		} catch (Exception e) {
			DataBase.rollback();
			e.printStackTrace();
			throw e;
		} finally {
			DataBase.releaseConnection(connection);
		}
		return flag;

	}
	
	public OrderDetial get(int id) throws Exception {
		Connection connection = null;
		OrderDetial orderDetial = null;
		try {
			orderDetial = new OrderDetial();
			connection = DataBase.getConn();
			orderDetialImpl.setConn(connection);
			orderDetial = orderDetialImpl.get(id);
			DataBase.commit();
		} catch (Exception e) {
			DataBase.rollback();
			e.printStackTrace();
			throw e;
		} finally {
			DataBase.releaseConnection(connection);
		}
		return orderDetial;

	}
	
	public int getCount(long orderid) throws Exception {
		Connection connection = null;
		int totalpage = 0;
		try {
			connection = DataBase.getConn();
			orderDetialImpl.setConn(connection);
			totalpage = orderDetialImpl.getCount(orderid);
			DataBase.commit();
		} catch (Exception e) {
			DataBase.rollback();
			e.printStackTrace();
			throw e;
		} finally {
			DataBase.releaseConnection(connection);
		}
		return totalpage;
	}

	public List<OrderDetial> list(int pageSize,int pageNo,long id) throws Exception {
		Connection connection = null;
		List<OrderDetial> orderDetiallist = null;
		try {
			orderDetiallist = new ArrayList<OrderDetial>();
			connection = DataBase.getConn();
			orderDetialImpl.setConn(connection);
			orderDetiallist = orderDetialImpl.list(pageSize,pageNo,id);
			DataBase.commit();
		} catch (Exception e) {
			DataBase.rollback();
			e.printStackTrace();
			throw e;
		} finally {
			DataBase.releaseConnection(connection);
		}
		return orderDetiallist;
	}
}
